package com.atnjupt.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.atnjupt.bean.Book;
import com.atnjupt.dao.BookDao;
import com.atnjupt.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    @Override
    public Boolean saveBook(Book book) {
        int insert = bookDao.insert(book);
        return insert > 0 ? true : false;
    }

    @Override
    public Boolean updateBook(Book book) {
       return bookDao.updateById(book) > 0 ? true : false;
    }

    @Override
    public Boolean delete(Integer integer) {
        return bookDao.deleteById(integer) > 0 ? true : false;
    }

    @Override
    public Book getBookById(Integer integer) {
        return bookDao.selectById(integer);
    }

    @Override
    public List<Book> getAllBooks() {
        return bookDao.selectList(null);
    }

    @Override
    public IPage<Book> getPage(Integer pageNum, Integer pageSize) {
        IPage iPage = new Page(pageNum,pageSize);
        bookDao.selectPage(iPage, null);
        return iPage;
    }
}
